using System;
using Velocity4Net.Runtime.Parse.AST;
using Velocity4Net.Ctx;
using System.IO;

namespace Velocity4Net.Runtime.Visitor
{
    /**
     * This is the base class for all visitors.
     * For each AST node, this class will provide
     * a bare-bones method for traversal.
     *
     * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
     * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
     * @version $Id: BaseVisitor.java 747106 2009-02-23 19:25:14Z nbubna $
     */
    public abstract class BaseVisitor : ParserVisitor
    {
        /** Context used during traversal */
        protected InternalContextAdapter context;

        /** Writer used as the output sink */
        protected TextWriter writer;

        /**
         * @param writer
         */
        public void setWriter(TextWriter writer)
        {
            this.writer = writer;
        }

        /**
         * @param context
         */
        public void setContext(InternalContextAdapter context)
        {
            this.context = context;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.SimpleNode, java.lang.Object)
         */
        public virtual Object visit(SimpleNode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTprocess, java.lang.Object)
         */
        public virtual Object visit(ASTprocess node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTExpression, java.lang.Object)
         */
        public virtual Object visit(ASTExpression node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTAssignment, java.lang.Object)
         */
        public virtual Object visit(ASTAssignment node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTOrNode, java.lang.Object)
         */
        public virtual Object visit(ASTOrNode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTAndNode, java.lang.Object)
         */
        public virtual Object visit(ASTAndNode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTEQNode, java.lang.Object)
         */
        public virtual Object visit(ASTEQNode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTNENode, java.lang.Object)
         */
        public virtual Object visit(ASTNENode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTLTNode, java.lang.Object)
         */
        public virtual Object visit(ASTLTNode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTGTNode, java.lang.Object)
         */
        public virtual Object visit(ASTGTNode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTLENode, java.lang.Object)
         */
        public virtual Object visit(ASTLENode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTGENode, java.lang.Object)
         */
        public virtual Object visit(ASTGENode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTAddNode, java.lang.Object)
         */
        public virtual Object visit(ASTAddNode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTSubtractNode, java.lang.Object)
         */
        public virtual Object visit(ASTSubtractNode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTMulNode, java.lang.Object)
         */
        public virtual Object visit(ASTMulNode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTDivNode, java.lang.Object)
         */
        public virtual Object visit(ASTDivNode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTModNode, java.lang.Object)
         */
        public virtual Object visit(ASTModNode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTNotNode, java.lang.Object)
         */
        public virtual Object visit(ASTNotNode node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIntegerLiteral, java.lang.Object)
         */
        public virtual Object visit(ASTIntegerLiteral node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTFloatingPointLiteral, java.lang.Object)
         * @since 1.5
         */
        public virtual Object visit(ASTFloatingPointLiteral node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTStringLiteral, java.lang.Object)
         */
        public virtual Object visit(ASTStringLiteral node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIdentifier, java.lang.Object)
         */
        public virtual Object visit(ASTIdentifier node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTMethod, java.lang.Object)
         */
        public virtual Object visit(ASTMethod node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTReference, java.lang.Object)
         */
        public virtual Object visit(ASTReference node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTTrue, java.lang.Object)
         */
        public virtual Object visit(ASTTrue node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTFalse, java.lang.Object)
         */
        public virtual Object visit(ASTFalse node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTBlock, java.lang.Object)
         */
        public virtual Object visit(ASTBlock node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTText, java.lang.Object)
         */
        public virtual Object visit(ASTText node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIfStatement, java.lang.Object)
         */
        public virtual Object visit(ASTIfStatement node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTElseStatement, java.lang.Object)
         */
        public virtual Object visit(ASTElseStatement node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTElseIfStatement, java.lang.Object)
         */
        public virtual Object visit(ASTElseIfStatement node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTComment, java.lang.Object)
         */
        public virtual Object visit(ASTComment node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTObjectArray, java.lang.Object)
         */
        public virtual Object visit(ASTObjectArray node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTWord, java.lang.Object)
         */
        public virtual Object visit(ASTWord node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTSetDirective, java.lang.Object)
         */
        public virtual Object visit(ASTSetDirective node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTDirective, java.lang.Object)
         */
        public virtual Object visit(ASTDirective node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTEscapedDirective, java.lang.Object)
         * @since 1.5
         */
        public virtual Object visit(ASTEscapedDirective node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTEscape, java.lang.Object)
         * @since 1.5
         */
        public virtual Object visit(ASTEscape node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTMap, java.lang.Object)
         * @since 1.5
         */
        public virtual Object visit(ASTMap node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIntegerRange, java.lang.Object)
         * @since 1.5
         */
        public virtual Object visit(ASTIntegerRange node, Object data)
        {
            data = node.childrenAccept(this, data);
            return data;
        }
    }
}
